package com.eusoft.demo.service.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.eusoft.demo.entity.User;
import com.eusoft.demo.mapper.UserMapper;
import com.eusoft.demo.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author eusoft
 * @since 2021-10-12
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User login(User user) {
        User userDB = userMapper.login(user);

        if(userDB!=null){
            return userDB;
        }

        throw new RuntimeException("用户名/密码错误~~");
    }

    @Override
    public List<User> getOtherUserList(Integer aid) {
        try{
            List<User> userList = userMapper.getOtherUserList(aid);
            return userList;
        }
        catch (Exception e){
            log.error(e.getMessage());
            throw new RuntimeException("未获取到数据");
        }

    }

    @Override
    public User getUserByAid(Integer aid) {
        try{
            User user = userMapper.getUserByAid(aid);
            return user;
        }
        catch (Exception e){
            log.error(e.getMessage());
            throw new RuntimeException("未获取到用户");
        }
    }
}
